package cn.westv.scps.web.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.yunpian.sdk.api.SmsApi;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsBatchSend;
import com.yunpian.sdk.model.SmsSingleSend;

import cn.westv.scps.constant.DBconstant;
import cn.westv.scps.constant.SmsTplCodeConstant;
import cn.westv.scps.domain.SmsMessageRecordEntity;
import cn.westv.scps.domain.SmsTemplateEntity;
import cn.westv.scps.exception.NoHaveValidateCode;
import cn.westv.scps.exception.SendSmsOutOfRangeException;
import cn.westv.scps.exception.SendSmstooFrequently;
import cn.westv.scps.exception.UnfoundSmsTplException;
import cn.westv.scps.exception.ValiDateCodeTimeout;
import cn.westv.scps.exception.ValidateCodeErr;
import cn.westv.scps.service.sms.masage.ISmsMessageService;
import cn.westv.scps.service.sms.template.ISmsTemplateService;
import cn.westv.scps.utils.PropertiesUtil;
import cn.westv.scps.utils.SpringContextUtil;
import cn.westv.scps.utils.StringUtils;
import cn.westv.scps.yunpian.Yunpian;

public class SendSmsTools {
	private ISmsMessageService smsMessageService;
	private ISmsTemplateService smsTemplateService;
	private Yunpian yp;
	private SmsApi smsApi;

	public SendSmsTools() {
		smsTemplateService = (ISmsTemplateService) SpringContextUtil.getBean("smsTemplateServiceImpl");
		smsMessageService = (ISmsMessageService) SpringContextUtil.getBean("smsMessageServiceImpl");
		smsApi = new SmsApi();
		yp = new Yunpian();
		smsApi.init(yp.getClnt());
	}

	/**
	 * 图片验证码的集合
	 */
	public static Map<String, Map<String, Object>> imgValidateMap = new Hashtable<>();
	/**
	 * 手机短信验证码的集合
	 */
	public static Map<String, Map<String, Map<String, Object>>> mobileValidateMap = new Hashtable<>();
	/**
	 * 记录每个手机发送短信次数记录的map集合
	 */
	public static Map<String, Map<String, Integer>> mobileSendAlarmCountMap = new HashMap<>();
	/**
	 * 记录每个手机发送验证码次数记录的map集合
	 */
	public static Map<String, Map<String, Integer>> mobileSendVerificationCountMap = new HashMap<>();
	/**
	 * 游客发送登录短信验证的次数记录
	 */
	public static Map<String, Integer> visitorLoginSendSmsCountMap = new HashMap<>();

	/**
	 * 创建流水号
	 *
	 * @param sendTime
	 * @return
	 */
	public static String makeSerialNumber(Date sendTime) {
		char c1 = (char) ((((int) (Math.random() * 25) + 1) + 65));
		// 生产随机的大写字母（65-90之间的数字）
		char c2 = (char) ((((int) (Math.random() * 25) + 1) + 65));
		// 生产随机的大写字母（65-90之间的数字）
		String serialNumber = "YunPian-" + c1 + "" + c2 + sendTime.getTime();
		return serialNumber;
	}

	/**
	 * 获取图片验证
	 *
	 * @param tokenCode
	 *            身份码(不能为空)
	 * @param out
	 *            输出流，生成的图片放入这个输出流中(默认ByteArrayOutputStream)
	 * @param width
	 *            高(默认100)
	 * @param height
	 *            宽(默认30)
	 * @param fontSize
	 *            字体大小(默认30)
	 * @param lineCount
	 *            干扰线数量(默认50)
	 * @return
	 * @throws IOException
	 */
	public ValidateCode createImgCode(final String tokenCode, OutputStream out, int width, int height, int fontSize,
			int lineCount) throws IOException {
		if (StringUtils.isEmpty(tokenCode)) {
			return null;
		}
		if (out == null) {
//			out = new ByteArrayOutputStream();
			return null;
		}
		if (width == 0) {
			width = 100;
		}

		if (height == 0) {
			height = 30;
		}
		if (fontSize == 0) {
			fontSize = 30;
		}
		if (lineCount == 0) {
			lineCount = 50;
		}
		// ValidateCode vCode = new ValidateCode(width, height, 0, fontSize,
		// lineCount);
		ValidateCode vCode = new ValidateCode(100, 30, 0, 30, 100);
		vCode.write(out);
		Map<String, Object> map = new HashMap<>();
		map.put("code", vCode.getCode());
		map.put("time", new Date());
		SendSmsTools.imgValidateMap.put(tokenCode, map);
		Runnable r = new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(60000L);// 等待1分钟，1分钟以后图片验证码失效
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				SendSmsTools.imgValidateMap.remove(tokenCode);
			}
		};
		Thread t = new Thread(r);
		t.start();
		// System.out.println("图片验证：" + tokenCode + "-" + vCode.getCode());
		return vCode;

	}

	/**
	 * 验证成功后，发送单条短信(手机类验证码短信)
	 *
	 * @param mobile
	 *            手机号
	 * @param imgCode
	 *            图片验证码
	 * @param tokenCode
	 *            身份代码
	 * @param time
	 *            超时时间
	 * @param smsTplCode
	 *            短信模板编码
	 * @return
	 */
	public Result<SmsSingleSend> sendSmsMassage(final String mobile, String imgCode, String tokenCode, final long time,
			String smsTplCode)
			throws SendSmstooFrequently, ValidateCodeErr, ValiDateCodeTimeout, UnfoundSmsTplException {
		// 图片验证码是一次使用以后就失效，不管能否验证成功，图片验证码都会失效
		Map<String, Object> remove = imgValidateMap.remove(tokenCode);// 删除映射，并获得验证码
		if (remove == null) {
			throw new ValidateCodeErr();
		}
		String code = (String) remove.get("code");
		Date codeTime = (Date) remove.get("time");
		if (StringUtils.isEmpty(imgCode)) {
			return null;
		}
		if (StringUtils.isEmpty(mobile)) {
			return null;
		}
		if (StringUtils.isEmpty(tokenCode)) {
			return null;
		}
		/**
		 * 判断该手机号码是否超过发送短信次数限制
		 */
		Map<String, Integer> mobileVerificationMap = mobileSendVerificationCountMap.get(mobile);// 根据手机号提取短信验证码次数map集合
		if (mobileVerificationMap != null) {
			Integer integer = mobileVerificationMap.get(smsTplCode);
			if (integer != null && integer >= 3) {
				throw new SendSmsOutOfRangeException();
			}
		}
		// if (smsTplCode.equals(SmsTplCodeConstant.VISITOR_LOGIN)) {//
		// 如果是游客登录，则判断是否超过次数限制
		// Integer count = visitorLoginSendSmsCountMap.get(mobile);
		// if (count != null && count >= 5) {
		// throw new SendSmsOutOfRangeException();
		// }
		// }
		// Integer count = mobileSendCountMap.get(mobile);
		// if (count != null && count > 7) {
		// throw new SendSmsOutOfRangeException();
		// }

		/**
		 * 判断上次发送短信到现在间隔是否超过1分钟
		 */
		String validateCode = "";
		Map<String, Map<String, Object>> tplMap = mobileValidateMap.get(mobile);
		if (tplMap == null) {
			tplMap = new HashMap<>();
			mobileValidateMap.put(mobile, tplMap);
		}
		Map<String, Object> validateMap = tplMap.get(smsTplCode);
		if (validateMap != null && validateMap.size() > 0) {
			Date date = (Date) validateMap.get("time");
			long now = System.currentTimeMillis();
			if ((now - date.getTime()) < 60000) {// 距离上次给该手机发送短信的时间小于1分钟，则不允许发送短信
				throw new SendSmstooFrequently();
			}
			// 判断之前的验证码是否存在，且是否已经超时，如果没有超时，则直接获取之前的，如果超时了，则这里不会获取，下面的代码会重新生成新的验证码
			if (validateMap.get("code") != null && validateMap.get("code") == "" && (now - date.getTime()) < 1200000L) {
				validateCode = (String) validateMap.get("code");
			}
		}

		if (!StringUtils.isNotBlank(code) || !code.equals(imgCode)) {// 判断是否通过图片验证
			throw new ValidateCodeErr();
		}
		if (new Date().getTime() - codeTime.getTime() > 60000) {// 如果图形验证码超过1分钟，则显示验证超时
			throw new ValiDateCodeTimeout();
		}
		List<SmsTemplateEntity> find = smsTemplateService.find("from SmsTemplateEntity where code = ?",
				SmsTemplateEntity.class, new Object[] { smsTplCode });
		if (find == null || find.size() < 1) {
			throw new UnfoundSmsTplException("找不到指定的短信模板，短信未发送！");
		}
		SmsTemplateEntity templateEntity = find.get(0);// 从数据库中找出短信模板
		String text = "【" + templateEntity.getCompany() + "】" + templateEntity.getContent();

		if (StringUtils.isEmpty(validateCode)) {// 如果验证码是空的，即之前没有获取过验证码，则随机生成
			for (int i = 0; i < 4; i++) {// 生成4位短信验证码
				int random = (((int) (Math.random() * 9 + 1) - 0));
				validateCode += random;
			}
		}
		Map<String, Object> map = new HashMap<>();
		map.put("code", validateCode);// 存入验证码
		map.put("time", new Date());// 存入当前时间
		map.put("smsTplCode", smsTplCode);// 存入短信模板
		tplMap = new HashMap<>();// 重新创建一个 该模板对应的短信验证
		tplMap.put(smsTplCode, map);
		mobileValidateMap.put(mobile, tplMap);// 将短信验证保存起来，15分钟以后验证失效
		text = text.replace("#code#", validateCode);// 完成短信内容的编辑
		String apikey = PropertiesUtil.getInstance().getPro("config/yunpian.properties", "yunpian_apikey");
		Map<String, String> param = new HashMap<>();
		param.put("apikey", apikey);
		param.put("text", text);
		param.put("mobile", mobile);
		Result<SmsSingleSend> rs = smsApi.single_send(param);// 发送短信
		yp.getClnt().close();// 关闭资源
		// 测试数据
		// Result<SmsSingleSend> rs = new Result<>();
		// rs.setCode(0);
		// System.out.println("模拟发送短信：" + param);
		// 测试数据
		SmsMessageRecordEntity messageRecordEntity = new SmsMessageRecordEntity();
		messageRecordEntity.setContent(text);
		messageRecordEntity.setMobile(mobile);
		messageRecordEntity.setReturnCode(rs.getCode());
		Date sendTime = new Date();
		messageRecordEntity.setSendTime(sendTime);
		String serialNumber = makeSerialNumber(sendTime);// 创建流水号
		messageRecordEntity.setSerialNumber(serialNumber);
		messageRecordEntity.setHandleState(DBconstant.NOT_HANDLE_ERR);// 一开始定义为短信失败且未处理

		if (rs.getCode() == 0) {
			// // 添加短信发送次数
			// if (count == null) {
			// count = 1;
			// }
			// mobileSendCountMap.put(mobile, ++count);
			// 如果是游客登录，则添加游客的登录次数
			// if (smsTplCode.equals(SmsTplCodeConstant.VISITOR_LOGIN)) {
			// Integer count = visitorLoginSendSmsCountMap.get(mobile);
			// if (count == null) {
			// count = 0;
			// }
			// count++;
			// visitorLoginSendSmsCountMap.put(mobile, count);
			// }

			// ---------------------保存用户发送验证码的次数----------------
			// 所有的验证码短信都集中在mobileSendVerificationCountMap中进行管理，所以游客登录的验证码次数代码就不再编写
			if (mobileVerificationMap == null) {
				mobileVerificationMap = new HashMap<>();// 保存模板对应次数的map集合
			}
			Integer sendCount = mobileVerificationMap.get(smsTplCode);// 获取这个验证码短信已经发送的次数
			if (sendCount == null) {// 如果为空，则认为这个验证码的短信没有发送过
				sendCount = 0;
			}
			sendCount++;
			mobileVerificationMap.put(smsTplCode, sendCount);// 存入次数
			mobileSendVerificationCountMap.put(mobile, mobileVerificationMap);// 更新mobile对应的map集合
			// ---------------------保存用户发送验证码的次数----------------

			messageRecordEntity.setHandleState(DBconstant.INITIAL_STAUTS);// 如果短信发送成功，则改为，短信发送成功，不需要处理
			Runnable r = new Runnable() {// 创建一天以后删除短信验证，即验证码失效，的线程
				@Override
				public void run() {
					try {
						Thread.sleep(time);// 等待时间，时间结束后删除手机短信验证码映射，即验证码失效
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					mobileValidateMap.remove(mobile);// 删除映射
				}
			};
			Thread t = new Thread(r);
			t.start();// 启动删除验证码线程
		}
		smsMessageService.saveOrUpdate(messageRecordEntity);// 添加短信记录
		if (rs.getCode() != 0) {
			// 短信发送失败

		}
		return rs;

	}

	/**
	 * 判断手机短息验证码是否正确
	 *
	 * @param mobile
	 * @param validateCode
	 * @return 如果验证不通过，会抛出对应的异常类。如果不抛错误，则表明验证通过了，返回true
	 */
	public boolean checkMobileValidateCode(String mobile, String validateCode, String smsTplCode, long MaxTimeOut)
			throws ValidateCodeErr, ValiDateCodeTimeout, NoHaveValidateCode {
		Map<String, Map<String, Object>> tplMap = SendSmsTools.mobileValidateMap.get(mobile);
		if (tplMap == null || tplMap.size() == 0) {
			// 没有对应的手机验证码，返还错误
			throw new NoHaveValidateCode();
		}
		Map<String, Object> map = tplMap.get(smsTplCode);// 短信验证码并不会因为校验后失效,具体需要操作业务以后再进行失效处理
		if (map != null && map.size() > 0) {
			String code = (String) map.get("code");// 获取验证码
			Date time = (Date) map.get("time");// 获取发送短信时的时间对象
			String smsTplCode_O = (String) map.get("smsTplCode");// 发送短信的内容编码，如果发送的是注册验证码，想用来修改密码，那是不可能滴，哈哈哈！
			if (!validateCode.equals(code) || !smsTplCode.equals(smsTplCode_O)) {// 验证码不正确验证失效
				throw new ValidateCodeErr();
			}
			/**
			 * 因为需求改为：所有的验证码的超时时间都是30分钟才失效，所以这里的代码失效时间都改为30分钟
			 */
			MaxTimeOut = 1800000L;
			if ((System.currentTimeMillis() - time.getTime()) > MaxTimeOut) {// 超过时间验证失效
				// 短信的验证码超时了，移除对应关系
				// SendSmsTools.mobileValidateMap.remove(mobile);// 删除短信验证码的对应关系
				throw new ValiDateCodeTimeout();
			}
		} else {
			// 没有对应的手机验证码，返还错误
			throw new NoHaveValidateCode();
		}

		return true;
	}

	/**
	 * 批量发送短信，内容相同
	 *
	 * @param mobiles
	 * @param text
	 * @return
	 */
	public Map<String, Object> sendBatchMessage(String[] mobiles, String text) {
		String mobileStr = "";
		Set<String> set = new HashSet<>();
		for (int i = 0; i < mobiles.length; i++) {
			set.add(mobiles[i].trim());// 对数组中的电话号码进行去重处理
		}
		for (String string : set) {
			mobileStr += string + ",";
		}
		mobileStr = mobileStr.substring(0, mobileStr.length() - 1);// 拼接成电话号码字符串
		Map<String, String> param = new HashMap<>();
		param.put("text", text);// 添加短信内容
		param.put("mobile", mobileStr);// 添加要发送的电话号码
		Result<SmsBatchSend> rs = smsApi.batch_send(param);// 发送短信，并返回发送结果
		if (rs != null) {
			Map<String, Object> map = new HashMap<>();
			Date sendTime = new Date();
			String serialNumber = makeSerialNumber(sendTime);
			List<SmsMessageRecordEntity> list = new ArrayList<>();
			int succeedCount = 0;
			int totalCount = mobiles.length;
			if (rs.getCode() == 0) {// 发送成功
				List<SmsSingleSend> data = rs.getData().getData();
				for (SmsSingleSend smsSingleSend : data) {
					SmsMessageRecordEntity entity = new SmsMessageRecordEntity();
					entity.setMobile(smsSingleSend.getMobile());
					entity.setReturnCode(smsSingleSend.getCode());
					entity.setContent(text);
					entity.setSendTime(sendTime);
					entity.setSerialNumber(serialNumber);
					list.add(entity);
					if (smsSingleSend.getCode() == 0) {
						succeedCount++;
						entity.setHandleState(DBconstant.SEND_SUCCEED);
					} else {
						entity.setHandleState(DBconstant.NOT_HANDLE_ERR);
					}
				}
			} else {// 发送失败
				for (String mobile : set) {
					SmsMessageRecordEntity entity = new SmsMessageRecordEntity();
					entity.setMobile(mobile);
					entity.setContent(text);
					entity.setSendTime(sendTime);
					entity.setSerialNumber(serialNumber);
					entity.setReturnCode(rs.getCode());
					entity.setHandleState(DBconstant.NOT_HANDLE_ERR);
					list.add(entity);
				}
			}
			smsMessageService.saveOrUpdateAll(list);
			map.put("result", rs);
			map.put("serialNumber", serialNumber);
			map.put("totalCount", totalCount);
			map.put("succeedCount", succeedCount);
			return map;
		}
		return null;
	}

	public static void main(String[] args) throws IOException, ParseException {
		// String logStr = "";
		// String dateTimeFormat =
		// UtilFuns.formatDateTimeCN(UtilFuns.dateTimeFormat(new Date(),
		// "yyyy年MM月dd日HH时mm分ss秒"));
		// File mkdirs = new File("D:/batch_send" + dateTimeFormat);
		// if (!mkdirs.exists()) {
		// mkdirs.mkdirs();
		// }
		// System.out.println(dateTimeFormat);
		// SmsApi smsApi = new SmsApi();
		// Yunpian yp = new Yunpian();
		// smsApi.init(yp.getClnt());
		// // String[] mobiles = { "13036425219", "13208301976", "13281621638",
		// // "13108055809", "15680246067", "18683095013",
		// // "15682330550", "18090189700", "18090189700", "18281198362",
		// // "15680246063", "15680246065", "18208398984",
		// // "15680246010", "18008228861", "13982433420", "15182506519",
		// // "15928282709", "18283016096", "18208389576",
		// // "15680246892", "15680246895", "15680246995", "15680248021",
		// // "15680248025", "15328328420", "18982445468",
		// // "13568629336", "18683047032", "15984016865", "15348213444",
		// // "18383023289", "15808303075", "17780116110",
		// // "15680246992", "13982453559", "15680246991", "15680246990",
		// // "15680246983", "13982752316", "15680246967",
		// // "15680246960", "13340742803", "13540333511", "18982401900",
		// // "13548344090", "18228993468", "18180309382",
		// // "13619040568", "13679686038", "18715780525", "15228234365",
		// // "13388287897", "18982442202", "18283075776",
		// // "15228210665", "13036545674", "15680246890", "15328339770",
		// // "18113550095", "18283073318", "15085083231",
		// // "13036542666", "13548369186", "17780111938", "13198262120",
		// // "15681556098", "13060143069", "15181999519",
		// // "18982497530", "18608302550", "13408209072", "15181984797",
		// // "18208370598", "15298263207", "13568639864",
		// // "15183083783", "18783052594", "15309083459", "18011641049",
		// // "15284075710", "13982779916", "15282475818",
		// // "18683091912", "15397678318", "13882713370", "18090198305",
		// // "18113576835", "15975350556", "18090860063",
		// // "13982443825", "18090860063", "13982443825", "13198863135",
		// // "15881954660", "18283069321", "13568135953",
		// // "18982451246", "13982449690", "17381443649", "13060143069",
		// // "15181999519", "13982795407", "13281630280",
		// // "15928287093", "18113555102", "15058110606", "18982780946",
		// // "17781047801", "18244360582", "18281199811",
		// // "17781000209", "15082064621", "15915535460", "18380933821",
		// // "18919519513", "17665262387", "18380951302",
		// // "18384012171", "18982457267", "18111175621", "13547374351",
		// // "15108183153", "15183029029", "15181991641",
		// // "18048683469", "18817437189", "18090884485", "13698152218",
		// // "13929248389", "18384367991", "18982732360",
		// // "18090174974", "18141312665", "13292161830", "13696116892",
		// // "13547368473", "18283096025", "13308935123",
		// // "18783006464", "15883010575", "18048681016", "15883078940",
		// // "15196054399", "18881540338", "18583006068",
		// // "15680241651", "15984432080", "18143467332", "13696110339",
		// // "18090182806", "15183022014", "18808308949",
		// // "15681526925", "15681578538", "15883061968", "18281189201",
		// // "18715702845", "15298268322", "18715896035",
		// // "15883072529", "13079111114", "18982741160", "18383023601",
		// // "17781001380", "18111193325", "18008203618",
		// // "13882767939", "18283002425", "18380926453", "15818099854",
		// // "15196058553", "13629046940", "13629046940",
		// // "18982440208", "18982440068", "15082060290", "18208396053",
		// // "18281140066", "18380958082", "13548375588",
		// // "18090188305", "15983011029", "13885791606", "17381400191",
		// // "17723315813", "15983029996", "13079157111",
		// // "18581860624", "18980591702" };
		// //
		// // String[] mobiles = { "18780120330", "17723315813", "18048562016",
		// // "18190781765", "18608000991" };
		// String[] mobiles = { "1804856201" };
		//
		// Set<String> set = new HashSet<>();
		// for (int i = 0; i < mobiles.length; i++) {
		// boolean add = set.add(mobiles[i].trim());
		// // System.out.println(add);
		// }
		// logStr += ("数组的长度是(原先的数量)：" + mobiles.length + "\r\n");
		// System.out.println("数组的长度是(原先的数量)：" + mobiles.length);
		// logStr += ("电话号码的数量是(去重复后数量)：" + set.size() + "\r\n");
		// System.out.println("电话号码的数量是(去重复后数量)：" + set.size());
		// String mobile = "";
		// for (String string : set) {
		// mobile += string + ",";
		// }
		// mobile = mobile.substring(0, mobile.length() - 1);
		// logStr += ("发送短信的号码是：" + mobile + "\r\n");
		// System.out.println("发送短信的号码是：" + mobile);
		// Map<String, String> param = new HashMap<>();
		// // param.put("apikey",
		// // PropertiesUtil.getInstance().getPro("config/yunpian.properties",
		// // "yunpian_apikey"));
		// param.put("mobile", mobile);// 添加要发送的电话号码
		// String text =
		// "【城市安全管家】尊敬的城市安全管家用户，由于泸州市古蔺县供电网络出现故障导致数据中心异常，工作人员正在紧急抢修。我们已于#date#临时暂停古蔺县二轮车防盗服务，这期间可能导致城市安全管家的APP和公众号不能正常使用，请见谅！在此期间请您妥善保管爱车，以免造成不必要的保险纠纷。系统一旦恢复运行，我们会立刻通知您，感谢您的理解与支持，如有疑问请致电：13038110808；08303380188；18090899903";
		// // String text = "ce";
		// text = text.replace("#date#", "2017年8月18日");
		// logStr += ("短信的内容是：\r\n======================\r\n" + text +
		// "\r\n=====================\r\n");
		// param.put("text", text);// 添加短信内容
		// Result<SmsBatchSend> rs = smsApi.batch_send(param);
		// logStr += ("云片返回的结果：\r\n---------------------------------\r\n" + rs
		// + "\r\n---------------------------------\r\n");
		// System.out.println(
		// "云片返回的结果：\r\n---------------------------------\r\n" + rs +
		// "\r\n---------------------------------\r\n");
		//
		// Integer code = rs.getCode();
		// if (code == 0) {
		// SmsBatchSend rsData = rs.getData();
		// List<SmsSingleSend> data = rsData.getData();
		// String succeedMobile = "";
		// String failMobile = "";
		// for (SmsSingleSend smsSingleSend : data) {
		// Integer code2 = smsSingleSend.getCode();
		// if (code2 == 0) {
		// logStr += ("\r\n" + smsSingleSend.getMobile() + "发送成功" + "\r\n");
		// System.out.println("\r\n" + smsSingleSend.getMobile() + "发送成功");
		// succeedMobile += "\"" + smsSingleSend.getMobile() + "\"" + ",";
		// } else {
		// logStr += ("\r\n" + smsSingleSend.getMobile() + "发送失败" + "\r\n");
		// System.out.println("\r\n" + smsSingleSend.getMobile() + "发送失败");
		// failMobile += "\"" + smsSingleSend.getMobile() + "\"" + ",";
		// }
		// }
		//
		// File succeedFile = new File("D:/batch_send" + dateTimeFormat +
		// "/succeed.txt");
		// if (!succeedFile.exists()) {
		// succeedFile.createNewFile();
		// }
		// File failFile = new File("D:/batch_send" + dateTimeFormat +
		// "/fail.txt");
		// if (!failFile.exists()) {
		// failFile.createNewFile();
		// }
		//
		// FileOutputStream out1 = new FileOutputStream(succeedFile);
		// out1.write(succeedMobile.getBytes());
		// out1.close();
		// FileOutputStream out2 = new FileOutputStream(failFile);
		// out2.write(failMobile.getBytes());
		// out2.close();
		//
		// } else {
		// logStr += ("短信发送失败！" + "\r\n");
		// System.out.println("短信发送失败！");
		// logStr += (rs.getThrowable() + "\r\n");
		// System.out.println(rs.getThrowable());
		// }
		// File logFile = new File("D:/batch_send" + dateTimeFormat +
		// "/log.txt");
		// if (!logFile.exists()) {
		// logFile.createNewFile();
		// }
		// FileOutputStream out3 = new FileOutputStream(logFile);
		// out3.write(logStr.getBytes());
		// out3.close();
		// yp.getClnt().close();
		String makeSerialNumber = makeSerialNumber(new Date());
		// System.out.println(makeSerialNumber);
	}
}
